<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class PatientOrRecordRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return \Auth::check();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'patient_id' => 'required_without:record_id|integer|min:1|exists:tn_user_base,id',
            'record_id'  => 'required_without:patient_id|integer|min:1|exists:st_medical_records,id',
        ];
    }

    public function messages()
    {
        return [
            'patient_id.required_without' => '患者ID和病历ID至少传一个',
            'patient_id.integer'          => '患者ID 必须是一个数字',
            'patient_id.min'              => '患者ID 必须大于等于 :min',
            'patient_id.exists'           => '提交的患者 不存在',

            'record_id.required_without' => '患者ID和病历ID至少传一个',
            'record_id.integer'          => '病历ID 必须是一个数字',
            'record_id.min'              => '病历ID 必须大于等于 :min',
            'record_id.exists'           => '请求的病历 不存在',
        ];
    }
}
